﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FileBrowse.aspx.cs" Inherits="AS.FilePicker.FileBrowse" %>
<%-- Register the FlashUpload control so we can use it below --%>
<%@ Register Assembly="FlashUpload" Namespace="FlashUpload" TagPrefix="FlashUpload" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
	<head id="Head1" runat="server">
		<meta http-equiv="Page-Enter" content="blendTrans(Duration=0.1)" />
		<meta http-equiv="Page-Exit" content="blendTrans(Duration=0.1)" />
		<meta http-equiv="Cache-Control" content="no-cache" />
		<meta http-equiv="Pragma" content="no-cache" />
		<title>File Picker</title>
		<meta http-equiv="EXPIRES" content="0" />
		<link href="submodal.css" rel="stylesheet" type="text/css" />
		<link href="jquery.Jcrop.css" rel="stylesheet" type="text/css" />
        <script src="jquery-1.3.2.js" type="text/javascript"></script>
        <script src="ui.core.js" type="text/javascript"></script>
        <script src="ui.draggable.js" type="text/javascript"></script>
        <script src="jquery.Jcrop.js" type="text/javascript"></script>
        <script src="submodalsource.js" type="text/javascript"></script>
        <script src="as-picker.js" type="text/javascript"></script>
		<link href="dialog.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="DialogHead.js"></script>
		<style type="text/css">	
			.row { HEIGHT: 22px }
			.cb { VERTICAL-ALIGN: middle }
			.itemimg { VERTICAL-ALIGN: middle }
			.editimg { VERTICAL-ALIGN: middle }
			.cell1 { VERTICAL-ALIGN: middle }
			.cell2 { VERTICAL-ALIGN: middle }
			.cell3 { PADDING-RIGHT: 4px; VERTICAL-ALIGN: middle; TEXT-ALIGN: right }
			.cb { }
		</style>
	</head>
	<body>
		<form runat="server" enctype="multipart/form-data" id="Form1"><div style="padding:10px; width:100%">
			<!-- start hidden -->
			<input type="hidden" runat="server" id="hiddenDirectory" name="hiddenDirectory" />
			<input type="hidden" runat="server" id="hiddenFile" name="hiddenFile" /> 
			<!-- end hidden -->
			<table border="0" cellspacing="0" cellpadding="0" width="100%">
				<tr>
					<td style="width:20">
<asp:Image id="Image1" Runat="server" ImageUrl="images/openfolder.gif"></asp:Image>
					</td>
					<td class="normal" style="width:260px;text-align:left">
<asp:Label Runat="server" id="FolderDescription"></asp:Label>
                    <div id="div_upload" style="display:none;position:absolute;BORDER: 1.5pt inset;background-color:#F7F3F7;top:32px;z-index:10000;width:575px;height:375px>
					    <FlashUpload:FlashUpload ID="flashUpload" runat="server" Width="575" Height="375"
                            UploadPage="Upload.axd" OnUploadComplete="UploadComplete()" 
                            FileTypeDescription="*.*" FileTypes="*.*" 
                            UploadFileSizeLimit="4000000" TotalUploadSizeLimit="1100000000" />
					</div>
					</td>
					<td valign="top" style="width:425px;">
					<img id="Upload" alt="Upload files" style="cursor:pointer" title="Upload files"
							src="images/publish.gif" onclick="Upload_click()" />
					
<img id="CreateDir" alt="Create directory" style="cursor:pointer" title="Create directory"
							src="images/newfolder.gif" onclick="CreateDir_click()" />
							
<img id="Copy" alt="Copy" style="cursor:pointer" title="Copy"
							src="images/copy.gif" onclick="Copy_click()" />
							
<img id="Move" alt="Move" style="cursor:pointer" title="Move"
							src="images/move.gif" onclick="Move_click()" />
							
<img class="dialogButton" style="cursor:pointer;" 
onclick="return ImageEditor()"
id="img_ImageEditor" src="images/imageeditor.gif" height="16px" alt="Image Editor" title="Image Editor" />

                    </td>
					<td>
					</td>
				</tr>
			</table>
			<table border="0" cellspacing="0" cellpadding="0" width="100%">
				<tr>
					<td valign="top" style="white-space:nowrap; width:300px;overflow:auto;">
						<div style="BORDER: 1.5pt inset;  VERTICAL-ALIGN: middle; OVERFLOW: auto; WIDTH: 300px; HEIGHT: 250px; Padding:0; BACKGROUND-COLOR: white">
							<asp:Table id="FoldersAndFiles" Runat="server" CellSpacing="1" CellPadding="0" Width="100%"
								CssClass="sortable">
								<asp:TableRow BackColor="#f0f0f0">
									<asp:TableHeaderCell Width="16px">
										<asp:ImageButton id="Delete" Runat="server" ToolTip="Delete files" AlternateText="Delete files" ImageUrl="images/s_cut.gif"
											OnClientClick="return deleteFile()" />
									</asp:TableHeaderCell>
									<asp:TableHeaderCell Width="16px">
										<asp:ImageButton id="DoRefresh" Runat="server" ToolTip="Refresh" AlternateText="Refresh" ImageUrl="images/s_refresh.gif"
											OnClick="DoRefresh_Click" />
									</asp:TableHeaderCell>
									<asp:TableHeaderCell id="name_Cell" Wrap="True" Width="145px" CssClass="filelistHeadCol" Font-Bold="False">Name</asp:TableHeaderCell>
									<asp:TableHeaderCell id="size_Cell" Width="62px" CssClass="filelistHeadCol" Font-Bold="False">Count/Size</asp:TableHeaderCell>
									<asp:TableHeaderCell id="op_Cell" Width="16px">&nbsp;</asp:TableHeaderCell>
									<asp:TableHeaderCell id="op_space" Width="1px"></asp:TableHeaderCell>
								</asp:TableRow>
							</asp:Table>
						</div>
						
						<table border="0" cellspacing="0" cellpadding="0" width="100%">
				<tr>
					
					<td valign="top">
					    <div style="margin-top:5px;">
						    &nbsp;&nbsp;File Url&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="TargetUrl" size="43" name="TargetUrl" runat="server" />
						</div>
						
						<div style="text-align:center;padding-top:5px;">
                        <asp:Button ID="Button1" runat="server"
                        OnClientClick="return checkFile()"
                         Text="   OK   " />
                        
                        &nbsp;&nbsp;&nbsp;
                        <input type="button" value="   Cancel  " onclick="return close_Frame()" id="Button2" />
						</div>
					</td>
				</tr>
			</table>
						
					</td>
					<td width="2px"></td>
					<td valign="top">
						<div style="BORDER: 1.5pt inset; VERTICAL-ALIGN: top; OVERFLOW: auto; WIDTH: 400px; HEIGHT: 300px; BACKGROUND-COLOR: white; TEXT-ALIGN: center;z-index:-1000">
							<div id="divpreview" style="BACKGROUND-COLOR: white;OVERFLOW: auto; WIDTH: 400px; HEIGHT: 300px;">
							    <img id="img_demo" alt="" src="images/1x1.gif" />
							</div>
						</div>
					</td>
				</tr>
				<tr>
					<td colspan="3" style="height:2">
					</td>
				</tr>
			</table>
			
			</div>
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" style="display:none">
            </asp:DropDownList>
		</form>
		
	</body>
	<script type="text/javascript" src="Dialog_InsertImage.js"></script>
</html>

<script type="text/javascript">

    function checkFile(){
        var imgUrl=document.getElementById("TargetUrl").value;
        if(imgUrl==""){
            alert("You must choose the file !");
            return false;
        }
        else{
            try{
                window.top.document.getElementById("<%=txtID%>").value = imgUrl;
                window.top.hidePopWin(false);
            }
            catch(err){
                try{
                    window.parent.document.getElementById("<%=txtID%>").value = imgUrl;
                    window.parent.hidePopWin(false);
                }
                catch(err1){
                    window.opener.document.getElementById("<%=txtID%>").value = imgUrl;
                    window.close();
                }
            }
        }
        return false;
    }
    
    function close_Frame(){
        try{
            window.top.document.getElementById("<%=txtID%>").value = window.top.document.getElementById("<%=txtID%>").value;
            window.top.hidePopWin(false);
        }
        catch(message){
            try{
                window.parent.document.getElementById("<%=txtID%>").value = window.parent.document.getElementById("<%=txtID%>").value;
                window.parent.hidePopWin(false);
            }
            catch(message1){
                window.close();
            }
        };
        return false;
    }
    
    function deleteFile(){
        var frm1 = document.forms[0];
        var arg="";
        for (i = 0; i < frm1.elements.length; i++)
        {
            if (frm1.elements[i].type == "checkbox")
            {   
                var chk = frm1.elements[i];
                if(chk.checked){                  
                    var checkName = frm1.elements[i].name;                   
                    if(checkName.indexOf("row")!=-1)
                    {
                        var idRow = checkName.split("$")[0];
                        var row = document.getElementById(idRow);
                        var objUrl = row.getAttribute("path");
                        if(arg=="")
                            arg = objUrl;
                        else
                            arg = arg + "," + objUrl;
                    }
                }
            }
        }
        if(arg=="")
            alert("You must choose the files or the folders to delete !");
        else{
            if(confirm("Are you sure to delete ?")){
                for (i = 0; i < frm1.elements.length; i++)
                {
                    if (frm1.elements[i].type == "checkbox")
                    {   
                        var chk = frm1.elements[i];
                        chk.checked = false;
                    }
                }
                __doPostBack("xoafile",arg);
            }
        }
        return false;
    }
    
    function ImageEditor(){
        var imgUrl=document.getElementById("TargetUrl").value;
        
        var imgObj=document.getElementById("img_demo");
        
        if(imgUrl=="" || imgUrl=="images/1x1.gif")
        {
            alert("Bạn chưa chọn file ảnh để crop");
            return false;
        }
        
        var wImg = imgObj.width + 40;
        var hImg = imgObj.height + 50;
        var left   = (screen.width  - wImg)/2;
        var top    = (screen.height - hImg)/2;
        window.open('ImageEditor.aspx?url='+imgUrl+'&ssID=<%=ssID %>','mywindow','width='+wImg+',height='+hImg+',top='+top+',left='+left+',location=0,status=0,scrollbars=1,toolbar=0,resizable=1,menubar=0,titlebar=0')

        return false;
    }
    function Refresh_onclose(t){
        __doPostBack("refresh",t) ;
    }
    
    function Move_click(){
	var frm1 = document.forms[0];
	var arg="";
	for (i = 0; i < frm1.elements.length; i++)
	{
		if (frm1.elements[i].type == "checkbox")
		{   
			var chk = frm1.elements[i];
			if(chk.checked){                  
				var checkName = frm1.elements[i].name;                   
				if(checkName.indexOf("row")!=-1)
				{
					var idRow = checkName.split("$")[0];
					var row = document.getElementById(idRow);
					var objUrl = row.getAttribute("path");
					if(arg=="")
						arg = objUrl;
					else
						arg = arg + "," + objUrl;
				}
			}
		}
	}
	if(arg=="")
		alert("You must choose the files or the folders to move !");
	else{
		if(confirm("Are you sure to move ?")){
			for (i = 0; i < frm1.elements.length; i++)
			{
				if (frm1.elements[i].type == "checkbox")
				{   
					var chk = frm1.elements[i];
					chk.checked = false;
				}
			}
			
			var dirName = prompt("Specify the relative path to move to : ", "<%=rootDir %>");
			if(dirName==null)
				return;
			else if(dirName=="")
				alert("You must input the relative path to move to");
			else{
				arg = dirName + "," + arg;
				__doPostBack("move",arg) ;
			}
		}
	}
	
	
}  ; 

function Copy_click(){
	var frm1 = document.forms[0];
	var arg="";
	for (i = 0; i < frm1.elements.length; i++)
	{
		if (frm1.elements[i].type == "checkbox")
		{   
			var chk = frm1.elements[i];
			if(chk.checked){                  
				var checkName = frm1.elements[i].name;                   
				if(checkName.indexOf("row")!=-1)
				{
					var idRow = checkName.split("$")[0];
					var row = document.getElementById(idRow);
					var objUrl = row.getAttribute("path");
					if(arg=="")
						arg = objUrl;
					else
						arg = arg + "," + objUrl;
				}
			}
		}
	}
	if(arg=="")
		alert("You must choose the files or folders to copy !");
	else{
		for (i = 0; i < frm1.elements.length; i++)
		{
			if (frm1.elements[i].type == "checkbox")
			{   
				var chk = frm1.elements[i];
				chk.checked = false;
			}
		}
		
		var dirName = prompt("Specify the relative path to copy to : ", "<%=rootDir %>");
		if(dirName==null)
			return;
		else if(dirName=="")
			alert("You must input the relative path to copy to !");
		else{
			arg = dirName + "," + arg;
			__doPostBack("copy",arg) ;
		}
	}
}  ; 

function UploadComplete(){
    alert("Upload completed");
    __doPostBack("refresh",'') ;
}
function Upload_click(){
    $("#div_upload").animate({"height": "toggle"}, { duration: 1000 });
}

$(window).load(function(){
    var objUrl = document.getElementById("TargetUrl").value;
    document.getElementById("img_ImageEditor").style.display = "none";
    if(objUrl != ""){
        var listArray = objUrl.split(".");
		var ext = listArray[listArray.length - 1].toLowerCase();
		if(ext == "bmp" || ext == "cgm" || ext == "gif" || ext == "ief" || ext == "jpg" || ext == "jpeg" || ext == "jpe" || ext == "png" || ext == "svg" || ext == "tiff" || ext == "tif" || ext == "djvu" || ext == "djv" || ext == "wbmp" || ext == "ras" || ext == "ico" || ext == "pnm" || ext == "pbm" || ext == "pgm" || ext == "ppm" || ext == "rgb" || ext == "xbm" || ext == "xpm" || ext == "xwd"){
			var html = "";
			html += '<img id="img_demo" alt="" src="' + objUrl + '" />' ;
			document.getElementById("divpreview").innerHTML = html;
			document.getElementById("img_ImageEditor").style.display = "inline";
		}
		else if(ext == "flv" || ext == "mp4" || ext == "mp3"){
			var html = "";
			html += '<embed id="player" height="300" width="400" flashvars="file='+ objUrl + '&autostart=true&image=&dock=true" allowscriptaccess="always" allowfullscreen="true" quality="high" name="player" src="player.swf" type="application/x-shockwave-flash" wmode="transparent"/>';
            document.getElementById("divpreview").innerHTML = html;
		}
		else if(ext == "swf"){
			var html = "";
			var _link = "#";
			html += "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" id=\"obj1\" ";
            html += " codebase =\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" " + " border=\"0\" ";
			html += " width=\"400\"";
            html += " height=\"300\"";
            html += ">";
            html += " <param name=\"movie\" value=\"" + objUrl + "\"/> ";
            html += " <param name=\"quality\" value=\"High\"/> ";
            html += " <param name=\"wmode\" value=\"transparent\"/> ";
            html += " <param name=\"AllowScriptAccess\" value=\"always\"/> ";
            //html += " <param name=\"FlashVars\" value=\"link=" +_link + "\"/> ");
            html += "<embed allowscriptaccess=\"always\" wmode=\"transparent\" src=\"" + objUrl + "\"  flashvars=\"link=" + _link + "\" ";

            html += " pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" ";
			html += " width=\"400\"";
            html += " height=\"300\"";
            html += "/>";
            html += "</object> ";
            document.getElementById("divpreview").innerHTML = html;
		}
		else if(ext == "avi" || ext == "mpeg" || ext == "mpg" || ext == "mp1" || ext == "mp2" || ext == "3gp" || ext == "asf" || ext == "asx" || ext == "wmv" || ext == "wma" || ext == "wmx" || ext == "rmvb"){
			var html = "";
			html += "<object classid=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" id=\"mediaPlayer\" type=\"application/x-oleobject\" ";
            html += " codebase =\"'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'\" " + " border=\"0\" ";
            html += " width=\"400\"";
            html += " height=\"300\"";
            html += ">";
            html += " <param name=\"fileName\" value=\"" + objUrl + "\"/> ";
            html += " <param name=\"uiMode\" value=\"none\"/> ";
            html += " <param name=\"autostart\" value=\"true\"/> ";
            html += " <param name=\"showControls\" value=\"true\"/> ";

            html += "<EMBED pluginspage=\"http://microsoft.com/windows/mediaplayer/en/download/\" id=\"mediaPlayer\" name=\"mediaPlayer\" ";
            html += " width=\"400\"";
            html += " height=\"300\"";
            html += " src=\"" + objUrl + "\" type=\"application/x-mplayer2\" displaysize=\"4\" autosize=\"-1\"  showcontrols=\"1\" showtracker=\"1\" showdisplay=\"1\" showstatusbar=\"0\" videoborder3d=\"-1\" uiMode=\"none\" autostart=\"true\" designtimesp=\"5311\"   ></embed>";
            html += "</object>";
            document.getElementById("divpreview").innerHTML = html;
		}
		else{
			document.getElementById("divpreview").innerHTML = objUrl;
		}
    }
    var FoldersAndFiles=document.getElementById("FoldersAndFiles");
    var Ox364=FoldersAndFiles.getElementsByTagName(Chh_Arr[0x22]);
    for(var i=0x0;i<Ox364[Chh_Arr[0x23]];i++)
    {
        var row=Ox364[i]; 
        var Url = row.getAttribute("Url");
        if(Url == objUrl){
            row.bgColor = "eeeeee";
            row.focus();
            break;
        }
    }
});
</script>

